//
//  CHCameraUIView.m
//  proofSdkProj
//
//  Created by cyptt on 2022/3/10.
//

#import "CHCameraUIView.h"
#import "CHStatusBarUtil.h"
@interface CHCameraUIView()
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewLayout;
@property (weak, nonatomic) IBOutlet UIButton *palyBtn;
@property (weak, nonatomic) IBOutlet UIButton *frashBtn;
@property (weak, nonatomic) IBOutlet UIButton *transferBtn;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;


@end

@implementation CHCameraUIView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
        
    }
    return self;
}

-(void)setUp{
    
    self.topViewLayout.constant = 44 +[CHStatusBarUtil getStatusBarHight];
  
   
}

-(void)dealloc{
    if (self.uiManage) {
        [self.uiManage removeObserver:self forKeyPath:@"timeStr"];
    }
 
}
-(void)setUiManage:(CHCameraUIManage *)uiManage{
    _uiManage = uiManage;

    [_uiManage addObserver:self forKeyPath:@"timeStr" options:NSKeyValueObservingOptionNew   context:@"cdd"];
    
    if (uiManage.recordPhotoType == CH_RECORD_PHOTO_TYPE_PHOTO) {
        UIImage * img = [UIImage imageNamed:@"camera_defalut_scca_jz" inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
        [self.palyBtn setImage:img forState:UIControlStateNormal];
    }
    self.timeTitleL.hidden = YES;
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    if ([keyPath isEqualToString:@"timeStr"]) {
        CHCameraUIManage * uimanage = object;
        self.timeTitleL.text = uimanage.timeStr;
    }
}



- (IBAction)playBtnClick:(UIButton *)sender {
    
    if (self.uiManage.recordPhotoType == CH_RECORD_PHOTO_TYPE_PHOTO) {
        [self.uiManage palyBtnClick:sender];
    }else{
        
        if (!sender.selected) {
            
            sender.selected = !sender.selected;
            self.cancelBtn.hidden = YES;
            self.transferBtn.hidden = YES;
            self.frashBtn.hidden = YES;
            self.timeTitleL.hidden = NO;
            [self.uiManage palyBtnClick:sender];
        }else{
            sender.selected = !sender.selected;
            self.cancelBtn.hidden = NO;
            self.transferBtn.hidden = NO;
            self.frashBtn.hidden = NO;
            self.timeTitleL.hidden = YES;
            [self.uiManage palyBtnClick:sender];
        }
       
//        sender.selected = !sender.selected;
//        if (sender.selected) {
//            self.cancelBtn.hidden = YES;
//            self.transferBtn.hidden = YES;
//            self.frashBtn.hidden = YES;
//            self.timeTitleL.hidden = NO;
//        }else{
//            self.cancelBtn.hidden = NO;
//            self.transferBtn.hidden = NO;
//            self.frashBtn.hidden = NO;
//            self.timeTitleL.hidden = YES;
//        }
      
    }
   
//
}
- (IBAction)frashBtnClick:(UIButton *)sender {
  
    [self.uiManage flashBtnClick: sender];
}
- (IBAction)transferBtnClick:(UIButton *)sender {

    sender.selected = !sender.selected;
    if (sender.selected) {
        
        self.frashBtn.hidden = YES;
        self.frashBtn.selected = NO;
    }else{
        self.frashBtn.hidden = NO;
    }
    [self.uiManage transferBtnClick:sender];
}
- (IBAction)cancelBtnClick:(id)sender {
  
 
    [self.uiManage cancelBtnclick:sender];
}


-(void)awakeFromNib{
    [super awakeFromNib];
    [self setUp];
}



-(void)btnClick:(UIButton *)btn{
    NSLog(@"点击了");
}
@end
